const express = require('express');
/* const mysql=require('mysql');
const db=mysql.createPool({
  host:'127.0.0.1',
  user:'root',
  password:'1998',
  database:'demo'
}) */
//创建实例
const app = express();
//注册解析路由body模块
app.use(express.urlencoded({ extended: false }))
//jsonp请求必须在cors模块之前，否则会被当做cors使用
app.get('/api/jsonp', (req, res) => {
  let funName = req.query.callback;
  console.log(funName);
  let data = { name: 'ming' };
  let contactFun = `${funName}(${JSON.stringify(data)})`;
  res.send(contactFun)
})
//导入cors跨域模块，或者在路由这种使用Access-Control-Allow-Origin请求头来解决跨域
const cors = require('cors')
app.use(cors())
// 导入路由模块
const ruter = require('./routers');

//注册路由模块
app.use('/api', ruter);
// 启动服务器
app.listen(8081, () => {
  console.log('Serving is Running');
})
